package com.danbay.framework.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

/**
 * 测试工具类
 * @author SJG
 * @date 2017/10/24
 */
public class TestUtils {

    /**
     * 根据Object的对象获取json的HttpEntity
     * @param data
     * @return
     * @throws JsonProcessingException
     */
    public static HttpEntity<String> getJsonHttpEntity(Object data) throws JsonProcessingException {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.valueOf("application/json;UTF-8"));
        String json=new ObjectMapper().writeValueAsString(data);
        HttpEntity<String> strEntity = new HttpEntity<String>(json,headers);
        return strEntity;
    }
}
